#include "mainwindow.h"
#include "ui_mainwindow.h"



MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    fins = new Fins;
    logger  = new Logger;

    logger->SetWhereFins(fins);

    Dno = new Heater ("Dno");
    Bok = new Heater ("Bok");
    Pit = new Heater ("Pit");
    Algo = new Algorithm ("Algo");
    Growth = new Heater("Growth");

    Dno->SetWhereFins(fins);
    Bok->SetWhereFins(fins);
    Pit->SetWhereFins(fins);
    Algo->SetWhereFins(fins);
    Growth->SetWhereFins(fins);

    ui->HLayout4Heat->addWidget(Dno);
    ui->HLayout4Heat->addWidget(Bok);
    ui->HLayout4Heat->addWidget(Pit);
    ui->HLayout4Heat->addWidget(Algo);

    ui->HLayoutGrowth->addWidget(Growth);

    KeyPressEater *keyPressEater = new KeyPressEater(this);

    QObject::connect(fins, SIGNAL(from_fins_out()), logger, SLOT(updateCaption()));

    InitFields();

//    spin->installEventFilter(keyPressEater);
    this->installEventFilter(keyPressEater);
   // spin->installEventFilter(this);
}



bool MainWindow::eventFilter(QObject *obj, QEvent *event)
{
    if (obj == spin)
    {
        if (event->type() == QEvent::KeyPress)
        {
            QKeyEvent *keyEvent = static_cast<QKeyEvent*>(event);
            qDebug() << "AAAAA key press" << keyEvent->key();
            return true;
        }
        else
        {
            return false;
        }
    }
    else
    {
        // pass the event on to the parent class
        return QMainWindow::eventFilter(obj, event);
    }
}

void MainWindow::spinValueChanged( int i )
{
  qDebug() << i;
}

MainWindow::~MainWindow()
{
  delete ui;
}


void MainWindow::on_ViewFins_clicked()
{
    fins->show();
}
//

void MainWindow::on_ViewLogger_clicked()
{
    logger->show();
}


void MainWindow::InitFields ()
{

}

void MainWindow::accept ()
{
    qDebug()<<"accept";
}


